LOG_I("File:\"\Product/script/src/class.lua\"    is running")
local _, _, majorv, minorv, rev = string.find(_VERSION, "(%d).(%d)[.]?([%d]?)")
local VersionNumber = tonumber(majorv) * 100 + tonumber(minorv) * 10 + (((string.len(rev) == 0) and 0) or tonumber(rev))

function setmt__gc(t, mt)
    if VersionNumber == 510 then
        local prox = newproxy(true);
        getmetatable(prox).__gc = function()
            mt.__gc(t);
        end
        t[prox] = true;
    end
    return setmetatable(t, mt);
end

--递归构造基类
function _ctorclass(cls, obj, ...)
    if cls ~= nil and obj ~= nil then
        if cls.superClss ~= nil then
            local superCount = #cls.superClss;
            for i = 1, superCount do
                local s = cls.superClss[i];
                _ctorclass(s, obj, ...);
            end
        end
        cls.ctor(obj, ...);
    end
end

function ctorclass(obj, ...)
    if obj ~= nil then
        _ctorclass(obj.class, obj, ...);
    end
end

--递归析构基类
function _dctorclass(cls, obj)
    if cls ~= nil and obj ~= nil then
        cls.dtor(obj);
        if cls.superClss ~= nil then
            local superCount = #cls.superClss;
            for i = 1, superCount do
                local s = cls.superClss[superCount - i + 1];
                _dctorclass(s, obj);
            end
        end
    end
end

function dtorclass(obj)
    if obj ~= nil then
        _dctorclass(obj.class, obj);
    end
end

function class(classname, ...)
    local cls = {};
    local superlist = {...};
    local supercount = table.getn(superlist);
    if supercount > 0  then --复制基类方法
        local clss_supers = {};
        local clss_super_byname = {};

        --单继承和多继承通用继承逻辑
        local i = 0;
        local supername = nil;
        for _, s in ipairs(superlist) do
            for k,v in pairs(s) do
                cls[k] = v;
            end;

            if i == 0 then
                supername = s.__cname;
            else
                supername = supername .. ",".. s.__cname;
            end
            i= i + 1;

            table.insert(clss_supers, s);
            clss_super_byname[s.__cname] = s;
        end

        cls.superClss = clss_supers;
        cls.superClsByName = clss_super_byname;
    else
        cls = {ctor = function() end, dtor = function() end};
    end

    cls.__cname = classname;
    cls.__index = cls
    cls.__gc = function(t)
        dtorclass(t);
    end

    function cls:new(...)
        --实例化
        local newtable = {};
        local instance = setmt__gc(newtable, cls);

        instance.class = cls;
        ctorclass(instance, ...);
        return instance;
    end

    return cls;
end



-- TVector = TVector or class("TVector")

-- function TVector:ctor()
    -- self.data = {};
-- end

-- function TVector:PushBack(value)
    -- table.insert(self.data, value);
-- end

-- function TVector:PopBack()
    -- if self:IsEmpty() then
        -- return nil;
    -- end

    -- local ln = #self.data;
    -- local value = self.data[ln];
    -- table.remove(self.data, ln);
    -- return value;
-- end

-- ---@return boolean
-- function TVector:Insert(i, value)
    -- local p = self.data[i];
    -- table.insert(self.data, i, value);
    -- if i ~= 1 and p == nil then      --下标为1的位置是肯定能插入的，但如果不是1，这个位置也没东西，那就插不进去了
        -- LOGE("TVector:Insert - invalid index %d", i);
        -- return false;
    -- else
        -- return true;
    -- end
-- end

-- ---@return boolean
-- function TVector:Remove(i)
    -- if table.remove(self.data, i) == nil then
        -- LOGE("TVector:Remove - invalid index %d", i);
        -- return false;
    -- else
        -- return true;
    -- end
-- end

-- function TVector:IsEmpty()
    -- if #self.data == 0 then
        -- return true;
    -- end
    -- return false;
-- end

-- function TVector:Set(i, v)
    -- if self.data[i] == nil then
        -- LOGE("TVector:Set - invalid index %d", i);
        -- return false;
    -- else
        -- self.data[i] = v;
        -- return true;
    -- end
-- end

-- function TVector:Get(i)
    -- return self.data[i];
-- end

-- ---@return number
-- function TVector:Size()
    -- return #self.data;
-- end

-- function TVector:Sort(func)
    -- if func == nil then
        -- table.sort(self.data);
    -- else
        -- table.sort(self.data, func);
    -- end
-- end

-- function TVector:Clear()
    -- self.data = {};
-- end